package com.tom.commonframework.common.base.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by TomLeisen on 2018/1/30 下午3:42
 * Email: xy162162a@163.com
 * Description: 项目跳转统一基类
 */

public class JumpUtil {


    public static void jump(Context context, Class<?> className) {
        jump(context, -1, className, null);
    }

    public static void jump(Context context, Class<?> className, Bundle bundle) {
        jump(context, -1, className, bundle);
    }

    public static void jump(Context context, int code, Class<?> className){
        jump(context, code, className, null);
    }

    public static void jump(Context context, int code, Class<?> className, Bundle bundle) {
        Intent intent = new Intent();
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        intent.setClassName(context, className.getName());
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (code > 0) {
                activity.startActivityForResult(intent, code);
            } else {
                activity.startActivity(intent);
            }
        } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//非activity，需要开新的任务栈
            context.startActivity(intent);
        }
    }

    public static void jump(Context context, Intent intent) {
        jump(context,intent,-1);
    }

    public static void jump(Context context, Intent intent,int code) {
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (code > 0) {
                activity.startActivityForResult(intent, code);
            } else {
                activity.startActivity(intent);
            }
        } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//非activity，需要开新的任务栈
            context.startActivity(intent);
        }
    }


}
